home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / MacApp / MacApp 2.0 CD Release / MacApp 2.0 (Many Libraries) / Libraries / UFailure.a < prev    next >
Encoding:
Text File  |  1990-03-27  |  3.3 KB  |  115 lines  |  [TEXT/MPS ]

  1. ;=============================================================================
  2. ; Failure Handler Assembly Routines
  3. ;
  4. ; KNOWN LIMITATIONS
  5. ;
  6. ; Copyright © 1984-1990 Apple Computer, Inc.  All rights reserved.
  7. ;
  8. ; when       who    what
  9. ; -------- ---- --------------------------------------------------------------
  10. ; 88.07.28 srf    add header and includes for Macros
  11. ; ----------------------------------------------------------------------------
  12.  
  13.                 Blanks        On
  14.                 String        AsIs
  15.                 Case        On
  16.  
  17.                 Print        Off
  18.                 Include     'Macros.a'
  19.  
  20.                 LOAD            'ProgStrucMacs.d'
  21.                 LOAD            'FlowCtlMacs.d'
  22.                 Print        On
  23.  
  24. ;---------------------------------------------------------------------------------------------------
  25.  
  26. UFailureGlobals Record
  27.                 Export        gAskAboutAlloc, gAskFailure
  28. gAskAboutAlloc    DC.W        0                    ; Boolean: ask about each allocation
  29. gAskFailure        DC.W        0                    ; Boolean: ask about failures
  30.                 EndR
  31.             
  32.             
  33. nSavedRegs        Equ         11
  34.  
  35.                 Seg         'MAFailureRes'
  36. ;-------------------------------------------------------------------
  37. ;PROCEDURE CatchFailures(VAR fi: FailInfo; PROCEDURE Handler(e: INTEGER; m: LONGINT)); EXTERNAL;
  38. ;-------------------------------------------------------------------
  39. CATCHFAILURES    Proc        Export
  40.                 DATA
  41.                 Export        gTopHandler:Data
  42. gTopHandler     DC.L        0            ;Pointer to the top level (most recent) handler
  43.                 CODE
  44.  
  45. A6Link            Equ         4                        ; static link which the Pascal compiler
  46.                                                     ; automatically pushes on the stack after
  47.                                                     ; pushing a ProcPtr ("PROCEDURE Handler")
  48. handler         Equ         A6Link + 4                ; the ProcPtr ("PROCEDURE Handler")
  49. fiVAR            Equ         handler + 4
  50. parmSize        Equ         fiVAR + 4 - A6Link
  51.  
  52.                 Head
  53.                 Move.L        fiVAR(SP),A0            ; get pointer to FailInfo block
  54.         
  55.                 MoveM.L     A2-A7/D3-D7,(A0)        ; save All regs first
  56.                 Add         #nSavedRegs*4,A0        ; advance pointer by # bytes regs
  57.         
  58.                 Clr.W        (A0)+                    ; clear error field
  59.                 Clr.L        (A0)+                    ; clear message field
  60.         
  61.                 Lea         A6Link(SP),A1            ; save the A6Link And Proc ptr
  62.                 Move.L        (A1)+,(A0)+             ; save the A6Link
  63.                 Move.L        (A1)+,(A0)+             ; save the Proc ptr
  64.         
  65.                 Move.L        gTopHandler(A5),(A0)+    ; Link the FailInfo into the LIST
  66.                 Move.L        fiVAR(SP),gTopHandler(A5)
  67.     If    qDebug Then
  68.                 Move.L        (SP),(A0)+                ; remember the caller's PC
  69.     EndIf
  70.  
  71. exit
  72.                 Move.L        (SP)+,A0
  73.                 Add.L        #parmSize,SP
  74.                 Jmp         (A0)
  75.                 Tail        CATCHFAILURES
  76.         
  77.  
  78.                 Seg         'MAFailureRes'
  79. ;-------------------------------------------------------------------
  80. ;PROCEDURE DoFailure(pf: PFailInfo); EXTERNAL;
  81. ;-------------------------------------------------------------------
  82. DOFAILURE        Proc        Export
  83.                 Import        FAILURE
  84.  
  85. pf                Equ         4
  86.  
  87.                 Head
  88.                 Move.L        pf(SP),A0                ; get pointer to FailInfo
  89.                 MoveM.L     (A0),A2-A7/D3-D7        ; restore regs (can't use A7 anymore)
  90.                 Add         #nSavedRegs*4,A0        ; advance pointer
  91.         
  92.                 Move.W        (A0)+,D0                ; get error
  93.                 Move.L        (A0)+,D1                ; And message
  94.                 MoveM.L     D0/D1,-(SP)             ; save for later use
  95.         
  96.                 Move.W        D0,-(SP)
  97.                 Move.L        D1,-(SP)                ; parameters to failure handler
  98.                 
  99.                 Move.L        (A0)+,D0                ; check the A6Link
  100.                 Beq.S        @1                        ; If NIL Then don't pass it
  101.                 Move.L        D0,-(SP)                ; Else Do pass it
  102. @1
  103.                 Move.L        (A0)+,A0                ; get address of failure handler
  104.         
  105.                 Jsr         (A0)                    ; call failure handler
  106.                 MoveM.L     (SP)+,D0/D1             ; get error & message back
  107.                 Move.W        D0,-(SP)
  108.                 Move.L        D1,-(SP)                ; parameters to Failure
  109.                 Jsr         FAILURE
  110.                 
  111.                 ; should Not return
  112.                 Tail    DOFAILURE
  113.         
  114.                 End
  115.